package com.aaa.service.impl;

import com.aaa.entity.TesterFpa;
import com.aaa.dao.TesterFpaDao;
import com.aaa.service.TesterFpaService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 性格测试者(TesterFpa)表服务实现类
 *
 * @author
 * @since 2022-07-06 11:25:47
 */
@Service("testerFpaService")
public class TesterFpaServiceImpl implements TesterFpaService {
    @Resource
    private TesterFpaDao testerFpaDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TesterFpa queryById(Integer id) {
        return this.testerFpaDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param testerFpa   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<TesterFpa> queryByPage(TesterFpa testerFpa, PageRequest pageRequest) {
        long total = this.testerFpaDao.count(testerFpa);
        return new PageImpl<>(this.testerFpaDao.queryAllByLimit(testerFpa, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param testerFpa 实例对象
     * @return 实例对象
     */
    @Override
    public TesterFpa insert(TesterFpa testerFpa) {
        this.testerFpaDao.insert(testerFpa);
        return testerFpa;
    }

    /**
     * 修改数据
     *
     * @param testerFpa 实例对象
     * @return 实例对象
     */
    @Override
    public TesterFpa update(TesterFpa testerFpa) {
        this.testerFpaDao.update(testerFpa);
        return this.queryById(testerFpa.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.testerFpaDao.deleteById(id) > 0;
    }

    @Override
    public List<Map<String, Object>> findTesterByPhone(String phone) {
        return testerFpaDao.findTesterByPhone(phone);
    }

    @Override
    public List<Map<String, Object>> findSasTesterByPhone(String phone) {
        return testerFpaDao.findSasTesterByPhone(phone);
    }

    @Override
    public List<Map<String, Object>> findSdsTesterByPhone(String phone) {
        return testerFpaDao.findSdsTesterByPhone(phone);
    }
}
